package com.tcm.smarthealth.config;

import com.tcm.smarthealth.service.ai.AiClient;
import com.tcm.smarthealth.service.ai.DeepSeekAiClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.reactive.function.client.WebClient;
import org.springframework.util.StringUtils;

@Configuration
public class AiClientConfig {

    @Bean
    public AiClient aiClient(AiProperties properties, DeepSeekAiClient deepSeekAiClient) {
        if (!properties.isEnabled()) {
            throw new IllegalStateException("AI 功能未启用，请检查配置 app.ai.enabled");
        }
        if (!StringUtils.hasText(properties.getApiKey())) {
            throw new IllegalStateException("AI 服务未配置有效的 API key，请检查配置 app.ai.api-key");
        }
        return deepSeekAiClient;
    }

    @Bean
    public WebClient.Builder webClientBuilder() {
        return WebClient.builder();
    }
}

